//
//  ViewController.m
//  test
//
//  Created by sunhaiyan on 15/12/22.
//  Copyright © 2015年 sunhaiyan. All rights reserved.
//

#import "SHYViewController.h"
#import "Caculator.h"

typedef int (^blocka)(int);

@interface SHYViewController ()<UITableViewDataSource,UITableViewDelegate>
{
    NSMutableArray *tableDataArray;
}
@property (nonatomic, copy) blocka a;
@property (nonatomic, copy) NSString *aa;

- (NSMutableArray *)tableDataArray;

- (void)setTableDataArray:(NSMutableArray *)newValue;

@end

@implementation SHYViewController


void extracted_function(NSMutableArray **tableDataArray_p, SHYViewController *object) {
    //    NSInteger indexInDataArray = 0;
    //    
    //    for (NSInteger i = indexInDataArray - 3; i < indexInDataArray + 3; i++) {
    //        if (i < 0 ) {
    //            continue;
    //        }
    //        NSLog(@"ssss");
    //    }
    *tableDataArray_p = [NSMutableArray array];
    for (int i = 0;  i < 15; i ++) {
        [*tableDataArray_p addObject:[NSString stringWithFormat:@"jskjkgja%d",i]];
    }
    [object initTableView];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.a = ^int (int a) {
        return 1;
    };
    Caculator *cacu = [[Caculator alloc] init];
    cacu.add(^(int a){
        a += 2;
        return a;
    }).add(^(int a) {
        a *= 5;
        return a;
    });
    
    [[cacu caculator:^int(int resu) {
        resu += 2;
        return resu;
    }] caculator:^int(int resu) {
        resu *= 5;
        return resu;
    }];
    NSLog(@"cacu:%d",cacu.result);
    
    UIButton *bottomButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [bottomButton setTitle:@"致电敬老专线" forState:UIControlStateNormal];
    [bottomButton setTitle:@"致电敬老专线" forState:UIControlStateHighlighted];
//    [bottomButton.titleLabel setFont:kFontSizeLarge];
    [bottomButton setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 12)];
    [bottomButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//    [bottomButton setTitleColor:kBottomButtonTextColor forState:UIControlStateHighlighted];
//    [bottomButton setImage:[UIImage imageNamedInTaxiBundle:@"older_phone_icon"] forState:UIControlStateNormal];
//    [bottomButton setImage:[UIImage imageNamedInTaxiBundle:@"older_phone_icon"] forState:UIControlStateHighlighted];
    [bottomButton setBackgroundColor:[UIColor clearColor]];

    [self.view addSubview:bottomButton];
    
//   UIButton * _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
//    [_commentBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//    _commentBtn.titleLabel.font = [UIFont systemFontOfSize:14];
//    [_commentBtn setImage:[UIImage imageNamed:@"Direction_icon.png"] forState:UIControlStateNormal];
////    [self cancelOrder:orderData];
//    [self.view addSubview:_commentBtn];
//    [_commentBtn setTitle:@"反馈取消原因" forState:UIControlStateNormal];
//    _commentBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -5, 0, 5);
//    _commentBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 88, 0, -88);
//    _commentBtn.frame = CGRectMake(0, 30, self.view.frame.size.width, 30);
    
//    _commentBtn.frame = CGRectMake(50, 50, 100, 100);
//    [_commentBtn setImage:[UIImage imageNamed:@"older_phone_icon_big"] forState:UIControlStateNormal];
//    [_commentBtn setTitle:@"联系司机" forState:UIControlStateNormal];
//    _commentBtn.imageEdgeInsets = UIEdgeInsetsMake(-10, 14, 10, 0);
//    _commentBtn.titleEdgeInsets = UIEdgeInsetsMake(26, -30, -26, 14.5);
//    _commentBtn.backgroundColor = [UIColor whiteColor];
//    _commentBtn.titleLabel.font = [UIFont systemFontOfSize:16];
//    [_commentBtn setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//    [self.view addSubview:_commentBtn];
//    self.view.backgroundColor = [UIColor redColor];
    // Do any additional setup after loading the view, typically from a nib.
    
//    [self someMethodThatTakesABlock:^int(int a) {
//        <#code#>
//    }]
    
//    :(<#returnType#> (^)(<#parameterTypes#>))<#blockName#>;
//    :(<#returnType#> (^)(<#parameterTypes#>))<#blockName#>;
//    extracted_function(&tableDataArray, self);
    
    
}
- (void)someMethodThatTakesABlock:(int (^)(int a))a {
    
}

#pragma mark - UITableView

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    NSLog(@"numberOfSectionsInTableView");
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSLog(@"numberOfRowsInSection:section:%ld",(long)section);
    return tableDataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"heightForRowAtIndexPath:index:%ld.%ld",(long)indexPath.row,(long)indexPath.section);
    return 30;
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"willDisplayCell:row:%ld.%ld",(long)indexPath.row,(long)indexPath.section);
    
    NSString *title = tableDataArray[indexPath.row];
    cell.textLabel.text = title;
}
- (void)tableView:(UITableView *)tableView didEndDisplayingCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath*)indexPath
{
    NSLog(@"didEndDisplayingCellrow:%ld.%ld",(long)indexPath.row,(long)indexPath.section);
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSLog(@"cellforRowrow:%ld.%ld",(long)indexPath.row,(long)indexPath.section);
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell ) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
    return cell;
}

- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;{
    NSLog(@"titleForHeaderInSectionsection:%ld",(long)section);
    return @"header";
}
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;{
    NSLog(@"titleForFooterInSectionsection:%ld",(long)section);
        return @"footer";
}

#pragma mark - header footer

- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0){
    UILabel *label = (UILabel *)view;
    label.text = @"headerView";
    NSLog(@"willDisplayHeaderViewsection:%ld",(long)section);
}
- (void)tableView:(UITableView *)tableView willDisplayFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0){
    UILabel *label = (UILabel *)view;
    label.text = @"FooterView";
//    label.opaque
    NSLog(@"willDisplayFooterViewsection:%ld",(long)section);

}
- (void)tableView:(UITableView *)tableView didEndDisplayingHeaderView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0){
    NSLog(@"didEndDisplayingHeaderViewsection:%ld",(long)section);

}
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section NS_AVAILABLE_IOS(6_0){
    NSLog(@"didEndDisplayingFooterViewsection:%ld",(long)section);

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    NSLog(@"heightForHeaderInSectionsection:%ld",(long)section);
    return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
      NSLog(@"heightForFooterInSectionsection:%ld",(long)section);
    return 20;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
     NSLog(@"viewForHeaderInSectionsection:%ld",(long)section);
    UILabel *label= [[UILabel alloc]init];
    return label;
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
      NSLog(@"viewForFooterInSectionsection:%ld",(long)section);
    UILabel *label= [[UILabel alloc]init];
    return label;
}
- (NSMutableArray *)tableDataArray {
    return tableDataArray;
}

- (void)setTableDataArray:(NSMutableArray *)newValue {
    tableDataArray = newValue;
}

@end
